//
//  UserListCell.m
//  MyClouds
//
//  Created by sarah doo on 13-8-9.
//  Copyright (c) 2013年 sarah doo. All rights reserved.
//

#import "UserListCell.h"

@interface UserListCell ()

@property (nonatomic, retain)UILabel *nameLabel;

@property (nonatomic, retain)UILabel *phoneLabel;

@property (nonatomic, retain)UILabel *emailLabel;

@end

@implementation UserListCell

@synthesize nameLabel, phoneLabel, emailLabel, model;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self createViews];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)createViews {
    UIView *view = [[UIView alloc] initWithFrame:self.contentView.frame];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 120, 35)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor  = [UIColor greenColor];
    self.nameLabel = label;
    [view addSubview:label];
    [label release];
    
    label = [[UILabel alloc] initWithFrame:CGRectMake(120, 5, view.frame.size.width - 90, 35)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor  = [UIColor greenColor];
    self.phoneLabel = label;
    [view addSubview:label];
    [label release];
    
    label = [[UILabel alloc] initWithFrame:CGRectMake(120, 45, view.frame.size.width - 90, 35)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor  = [UIColor blackColor];
    self.emailLabel = label;
    [view addSubview:label];
    [label release];
    [self.contentView addSubview:view];
    [view release];
}

- (void)setModel:(PersonInfo *)_model {
    if (model != _model) {
        [model release];
        model = [_model retain];
    }
    NSString *name = [NSString stringWithFormat:@"%@", model.personFirstName];
    NSLog(@"name --- %@", name);
    if ([name rangeOfString:@"(null)"].length != 0) {
        NSArray *array = [name componentsSeparatedByString:@"(null)"];
        NSString *test = [array componentsJoinedByString:@""];
        NSLog(@"test ------- %@",test);
        self.nameLabel.text = test;
    } else {
        self.nameLabel.text = name;
    }
    NSString *phone  = nil;
    if ([model.personPhones count] == 1) {
        phone = [model.personPhones objectAtIndex:0];
    }
    if ([model.personPhones count] > 1) {
        phone = [model.personPhones componentsJoinedByString:@","];

    }
    NSLog(@"phone ---- %@", phone);
    self.phoneLabel.text = phone;
    self.emailLabel.text = model.personEmail;
}

@end
